package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.LeaveTeacherStudent;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 离职老师带班的学生 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-12-19
 */
public interface LeaveTeacherStudentMapper extends BaseMapper<LeaveTeacherStudent> {
    /**
     * 获取离职老师带班的学生信息
     */
    @Select({"<script>",
            "SELECT",
            "t1.year_part,",
            "t1.`quarter` as quarter_num ,",
            "t1.school_id,",
            "t4.schoolmaster_id,",
            "t1.teacher_id,",
            "t1.subjects_id,",
            "t1.student_id",
            "FROM",
            "record_course AS t1",
            "INNER JOIN grade AS t2 ON t1.old_grade_id = t2.id",
            "INNER JOIN organization AS t3 ON t2.school_id = t3.id",
            "LEFT JOIN leave_teacher_student AS t4 ON t1.year_part = t4.year_part ",
            "AND t1.`quarter` = t4.quarter_num ",
            "AND t1.subjects_id = t4.subjects_id ",
            "AND t1.school_id = t4.school_id ",
            "WHERE",
            "t1.teacher_id = ${teacherId}",
            "AND t1.lesson_type = 1",
            "AND t1.deleted = 0",
            "AND t4.id IS NULL",
            "GROUP BY",
            "t1.student_id,",
            "t1.subjects_id,",
            "t1.year_part,",
            "t1.`quarter` ",
            "</script>"})
    public abstract List<LeaveTeacherStudent> leaveTeacherStudent(@Param("teacherId") Long teacherId);

}
